package org.rowan.infovis.soccer;

import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;
import com.sun.opengl.util.texture.TextureCoords;
import java.io.File;

public class Player {

    private float HEIGHT = 300f;
    private float WIDTH = 50f;
    private boolean precision;
    private double headColorValue = 0;
    private double armsColorValue = 0;
    private double chestColorValue = 0;
    private double torsoColorValue = 0;
    private double legsColorValue = 0;
    private double footColorValue = 0;
    private double soccerBallColorValue = 0;
    private int soccerBallLocationValue = 0;
    private Texture ball;
    private Texture ballForPlayer1;
    private Texture ballForPlayer2;
    private PlayerData player;
    private int playerNumber;

    private int ballLocation = 0;


    public Player()
    {
    }

    public Player(
            double torsoColorValue,
            double footColorValue) {
        this.torsoColorValue = torsoColorValue;
        this.footColorValue = footColorValue;
    }

    public Player(
            double headColorValue,
            double armsColorValue,
            double chestColorValue,
            double torsoColorValue,
            double legsColorValue,
            double footColorValue
            )
    {
        this.headColorValue = headColorValue;
        this.armsColorValue = armsColorValue;
        this.chestColorValue = chestColorValue;
        this.torsoColorValue = torsoColorValue;
        this.legsColorValue = legsColorValue;
        this.footColorValue = footColorValue;
    }
    private static int F_SCALE = 5;




    void draw(GL gl, int x, int y, PlayerData p)
    {
        this.player = p;

        /*
         * 1 = RED
         * 2 = ORANGE
         * 3 = YELLOW
         * 4 = GREEN
         */

        drawDrippleChart(gl, x, y);


        drawTorso(gl, x, y, torsoColorValue);

        drawRightArm(gl, x, y, armsColorValue);

        drawWaste(gl, x, y, legsColorValue);

        drawFace(gl, x, y, 0);

        drawHead(gl, x, y, headColorValue);

        drawLeftFoot(gl, x, y, footColorValue);

        drawRightFoot(gl, x, y, footColorValue);

        drawChest(gl, x, y, chestColorValue);

        drawLeftArm(gl, x, y, armsColorValue);

        drawExpression(gl, x, y);



        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);




        drawBallProtection(gl, x , SetBallScale(soccerBallLocationValue) + y, soccerBallColorValue);




    }


    private int SetBallScale(int value)
    {
        int scale = 0;
        switch(value)
        {
            case 1:
                scale = 0;
                break;
            case 2:
                scale = 50;
                break;
            case 3:
                scale = 100;
                break;
            case 4:
                scale = 150;
                break;
        }
        return scale;
    }



    private void drawDrippleChart(GL gl, int i, int j)
    {


        gl.glPushMatrix();
        gl.glTranslated(i + 9 * F_SCALE, j + -62 * F_SCALE, 0);
        gl.glRotated(90,0,0,1);


        gl.glColor3f(1f, 1f, 1f);

        gl.glBegin(GL.GL_LINES);
        gl.glVertex2d(0.0, 0.0);
        gl.glVertex2d(150.0, 0.0);
        gl.glEnd();

        gl.glColor3f(1f, 0f, 0f);
        gl.glBegin(GL.GL_LINES);
        gl.glVertex2d(0.0, -15.0);
        gl.glVertex2d(0.0, 15.0);
        gl.glEnd();

        gl.glPushMatrix();
        gl.glColor3f(1f, 0.563f, 0f);
        gl.glTranslated(50.0, 0.0, 0.0);
        gl.glBegin(GL.GL_LINES);
        gl.glVertex2d(0.0, -15.0);
        gl.glVertex2d(0.0, 15.0);
        gl.glEnd();
        gl.glPopMatrix();

        gl.glPushMatrix();
        gl.glColor3f(1f, 1f, 0f);
        gl.glTranslated(100.0, 0.0, 0.0);
        gl.glBegin(GL.GL_LINES);
        gl.glVertex2d(0.0, -15.0);
        gl.glVertex2d(0.0, 15.0);
        gl.glEnd();
        gl.glPopMatrix();

        gl.glPushMatrix();
        gl.glColor3f(0f, 1f, 0f);
        gl.glTranslated(150.0, 0.0, 0.0);
        gl.glBegin(GL.GL_LINES);
        gl.glVertex2d(0.0, -15.0);
        gl.glVertex2d(0.0, 15.0);
        gl.glEnd();
        gl.glPopMatrix();


        gl.glPopMatrix();

    }



    void draw(GL gl)
    {

        //drawSoccerBall(gl);

        drawBallProtection(gl, 500, 500, 0);


        drawTorso(gl, 400, 400, torsoColorValue);

        drawRightArm(gl, 400, 400, armsColorValue);

        drawWaste(gl, 400, 400, legsColorValue);

        drawFace(gl, 400, 400, 0);

        drawHead(gl, 400, 400, headColorValue);

        drawLeftFoot(gl, 400, 400, footColorValue);

        drawRightFoot(gl, 400, 400, footColorValue);

        drawChest(gl, 400, 400, chestColorValue);

        drawLeftArm(gl, 400, 400, armsColorValue);
        //drawBall(gl);


        drawExpression(gl, 400, 400);




    }


    private void fillStat(GL gl, double value) {
        float bar = (float) (value / 100) * HEIGHT;

        if (value > 0.0 && value <= 25.0/25.0) {
            gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
            gl.glColor3f(1f, 0f, 0f);
        } else if (value > 25.0/25.0 && value <= 50.0/25.0) {
            gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
            gl.glColor3f(1f, 0.563f, 0f);
        } else if (value > 50.0/25.0 && value <= 75.0/25.0) {
            gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
            gl.glColor3f(1f, 1f, 0f);
        } else if (value > 75.0/25.0 && value <= 100.0/25.0) {
            gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
            gl.glColor3f(0f, 1f, 0f);
        }
    }

    public void drawLeftArm(GL gl, int i, int j, double value) {

        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);

        fillStat(gl, value);

        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);


        //System.out.println(i * F_SCALE + 12);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 1 * F_SCALE, j + 5 * F_SCALE);
        gl.glVertex2f(i + 2 * F_SCALE, j + 10 * F_SCALE);
        gl.glVertex2f(i + 3 * F_SCALE, j + 20 * F_SCALE);
        gl.glVertex2f(i + 4 * F_SCALE, j + 23 * F_SCALE);
        gl.glVertex2f(i + 5 * F_SCALE, j + 25 * F_SCALE);
        gl.glVertex2f(i + 9 * F_SCALE, j + 16 * F_SCALE);
        gl.glVertex2f(i + 6 * F_SCALE, j + 8 * F_SCALE);
        gl.glVertex2f(i + 9 * F_SCALE, j + 5 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + 5 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 3 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 2 * F_SCALE);
        gl.glVertex2f(i + 12 * F_SCALE, j + 0 * F_SCALE);
        gl.glVertex2f(i + 8 * F_SCALE, j + 2 * F_SCALE);
        gl.glEnd();


        //Draw Outline
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);

        //System.out.println(i * F_SCALE + 12);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 1 * F_SCALE, j + 5 * F_SCALE);
        gl.glVertex2f(i + 2 * F_SCALE, j + 10 * F_SCALE);
        gl.glVertex2f(i + 3 * F_SCALE, j + 20 * F_SCALE);
        gl.glVertex2f(i + 4 * F_SCALE, j + 23 * F_SCALE);
        gl.glVertex2f(i + 5 * F_SCALE, j + 25 * F_SCALE);
        gl.glVertex2f(i + 9 * F_SCALE, j + 16 * F_SCALE);
        gl.glVertex2f(i + 6 * F_SCALE, j + 8 * F_SCALE);
        gl.glVertex2f(i + 9 * F_SCALE, j + 5 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + 5 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 3 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 2 * F_SCALE);
        gl.glVertex2f(i + 12 * F_SCALE, j + 0 * F_SCALE);
        gl.glVertex2f(i + 8 * F_SCALE, j + 2 * F_SCALE);
        gl.glEnd();


    }

    public void drawTorso(GL gl, int i, int j, double value) {

        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);


        fillStat(gl, value);


        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);


        //System.out.println(i * F_SCALE + 12);

        //Draw Bottom Torso
        gl.glPushMatrix();
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 11 * F_SCALE, j + -6 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + 12 * F_SCALE);

        gl.glVertex2f(i + 29 * F_SCALE, j + 11 * F_SCALE);
        gl.glVertex2f(i + 34 * F_SCALE, j + -1 * F_SCALE);
        gl.glVertex2f(i + 23 * F_SCALE, j + -6 * F_SCALE);
        gl.glEnd();
        gl.glPopMatrix();



        //Top Torso Draw
        gl.glPushMatrix();
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 9 * F_SCALE, j + 16 * F_SCALE);
        gl.glVertex2f(i + 5 * F_SCALE, j + 25 * F_SCALE);
        gl.glVertex2f(i + 13 * F_SCALE, j + 32 * F_SCALE);
        gl.glVertex2f(i + 14 * F_SCALE, j + 28 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 27 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 27 * F_SCALE);
        gl.glVertex2f(i + 18 * F_SCALE, j + 28 * F_SCALE);
        gl.glVertex2f(i + 20 * F_SCALE, j + 30 * F_SCALE);
        gl.glVertex2f(i + 21 * F_SCALE, j + 34 * F_SCALE);
        gl.glVertex2f(i + 31 * F_SCALE, j + 33 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + 20 * F_SCALE);


        gl.glVertex2f(i + 29 * F_SCALE, j + 11 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + 12 * F_SCALE);


         /*
        gl.glVertex2f(i + 29 * F_SCALE, j + 11 * F_SCALE);
        gl.glVertex2f(i + 34 * F_SCALE, j + -1 * F_SCALE);
        gl.glVertex2f(i + 23 * F_SCALE, j + -6 * F_SCALE);
        */


        gl.glEnd();
        gl.glPopMatrix();


        //Draw Torso Outline
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);

        //Draw Bottom Torso
        gl.glPushMatrix();
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 11 * F_SCALE, j + -6 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + 12 * F_SCALE);
        gl.glVertex2f(i + 29 * F_SCALE, j + 11 * F_SCALE);
        gl.glVertex2f(i + 34 * F_SCALE, j + -1 * F_SCALE);
        gl.glVertex2f(i + 23 * F_SCALE, j + -6 * F_SCALE);
        gl.glEnd();
        gl.glPopMatrix();

        //Top Torso Draw
        gl.glPushMatrix();
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 9 * F_SCALE, j + 16 * F_SCALE);
        gl.glVertex2f(i + 5 * F_SCALE, j + 25 * F_SCALE);
        gl.glVertex2f(i + 13 * F_SCALE, j + 32 * F_SCALE);
        gl.glVertex2f(i + 14 * F_SCALE, j + 28 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 27 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 27 * F_SCALE);
        gl.glVertex2f(i + 18 * F_SCALE, j + 28 * F_SCALE);
        gl.glVertex2f(i + 20 * F_SCALE, j + 30 * F_SCALE);
        gl.glVertex2f(i + 21 * F_SCALE, j + 34 * F_SCALE);
        gl.glVertex2f(i + 31 * F_SCALE, j + 33 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + 20 * F_SCALE);
        gl.glVertex2f(i + 29 * F_SCALE, j + 11 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + 12 * F_SCALE);
        gl.glEnd();
        gl.glPopMatrix();




    }

    public void drawChest(GL gl, int i, int j, double value) {
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);
        fillStat(gl, value);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 15 * F_SCALE, j + 8 * F_SCALE);
        gl.glVertex2f(i + 12 * F_SCALE, j + 20 * F_SCALE);
        gl.glVertex2f(i + 24 * F_SCALE, j + 23 * F_SCALE);
        gl.glVertex2f(i + 27 * F_SCALE, j + 11 * F_SCALE);
        gl.glEnd();

        //Draw Outline
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 15 * F_SCALE, j + 8 * F_SCALE);
        gl.glVertex2f(i + 12 * F_SCALE, j + 20 * F_SCALE);
        gl.glVertex2f(i + 24 * F_SCALE, j + 23 * F_SCALE);
        gl.glVertex2f(i + 27 * F_SCALE, j + 11 * F_SCALE);
        gl.glEnd();

    }

    public void drawRightArm(GL gl, int i, int j, double value) {

        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);


        fillStat(gl, value);

        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);


        //System.out.println(i * F_SCALE + 12);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 30 * F_SCALE, j + 20 * F_SCALE);
        gl.glVertex2f(i + 31 * F_SCALE, j + 33 * F_SCALE);
        gl.glVertex2f(i + 42 * F_SCALE, j + 28 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + 21 * F_SCALE);
        gl.glEnd();


        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 58 * F_SCALE, j + 19 * F_SCALE);
        gl.glVertex2f(i + 60 * F_SCALE, j + 18 * F_SCALE);
        gl.glVertex2f(i + 64 * F_SCALE, j + 19 * F_SCALE);
        gl.glVertex2f(i + 64 * F_SCALE, j + 15 * F_SCALE);
        gl.glVertex2f(i + 65 * F_SCALE, j + 15 * F_SCALE);
        gl.glVertex2f(i + 65 * F_SCALE, j + 14 * F_SCALE);
        gl.glVertex2f(i + 61 * F_SCALE, j + 13 * F_SCALE);
        gl.glVertex2f(i + 60 * F_SCALE, j + 12 * F_SCALE);
        gl.glVertex2f(i + 58 * F_SCALE, j + 13 * F_SCALE);
        gl.glVertex2f(i + 54 * F_SCALE, j + 15 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + 21 * F_SCALE);
        gl.glVertex2f(i + 42 * F_SCALE, j + 28 * F_SCALE);
        gl.glEnd();



        //Draw Outline of Right Arm
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 30 * F_SCALE, j + 20 * F_SCALE);
        gl.glVertex2f(i + 31 * F_SCALE, j + 33 * F_SCALE);
        gl.glVertex2f(i + 42 * F_SCALE, j + 28 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + 21 * F_SCALE);
        gl.glEnd();


        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 58 * F_SCALE, j + 19 * F_SCALE);
        gl.glVertex2f(i + 60 * F_SCALE, j + 18 * F_SCALE);
        gl.glVertex2f(i + 64 * F_SCALE, j + 19 * F_SCALE);
        gl.glVertex2f(i + 64 * F_SCALE, j + 15 * F_SCALE);
        gl.glVertex2f(i + 65 * F_SCALE, j + 15 * F_SCALE);
        gl.glVertex2f(i + 65 * F_SCALE, j + 14 * F_SCALE);
        gl.glVertex2f(i + 61 * F_SCALE, j + 13 * F_SCALE);
        gl.glVertex2f(i + 60 * F_SCALE, j + 12 * F_SCALE);
        gl.glVertex2f(i + 58 * F_SCALE, j + 13 * F_SCALE);
        gl.glVertex2f(i + 54 * F_SCALE, j + 15 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + 21 * F_SCALE);
        gl.glVertex2f(i + 42 * F_SCALE, j + 28 * F_SCALE);
        gl.glEnd();


    }

    public void drawWaste(GL gl, int i, int j, double value) {

        //Draw Left Leg of Waste
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);

        fillStat(gl, value);

        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);


        //System.out.println(i * F_SCALE + 12);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 25 * F_SCALE, j + -38 * F_SCALE);
        gl.glVertex2f(i + 24 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 22 * F_SCALE, j + -29 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + -22 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + -6 * F_SCALE);
        gl.glVertex2f(i + 23 * F_SCALE, j + -6 * F_SCALE);

        gl.glVertex2f(i + 26 * F_SCALE, j + -15 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -34 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -36 * F_SCALE);
        gl.glVertex2f(i + 28 * F_SCALE, j + -38 * F_SCALE);
        gl.glVertex2f(i + 25 * F_SCALE, j + -38 * F_SCALE);
        gl.glEnd();



        //Draw Right Leg of Waste
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);

        fillStat(gl, value);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 34 * F_SCALE, j + -1 * F_SCALE);
        gl.glVertex2f(i + 39 * F_SCALE, j + -16 * F_SCALE);
        gl.glVertex2f(i + 40 * F_SCALE, j + -27 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -29 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 40 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 37 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 35 * F_SCALE, j + -32 * F_SCALE);
        gl.glVertex2f(i + 28 * F_SCALE, j + -18 * F_SCALE);

        gl.glVertex2f(i + 26 * F_SCALE, j + -15 * F_SCALE);
        gl.glVertex2f(i + 23 * F_SCALE, j + -6 * F_SCALE);
        gl.glVertex2f(i + 34 * F_SCALE, j + -1 * F_SCALE);

        /*
        gl.glVertex2f(i + 26 * F_SCALE, j + -15 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -34 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -36 * F_SCALE);
        gl.glVertex2f(i + 28 * F_SCALE, j + -38 * F_SCALE);
        gl.glVertex2f(i + 25 * F_SCALE, j + -38 * F_SCALE);
         * */

        gl.glEnd();



        //Draw the Outline of the Waste
        //Draw Left Leg of Waste
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 25 * F_SCALE, j + -38 * F_SCALE);
        gl.glVertex2f(i + 24 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 22 * F_SCALE, j + -29 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + -22 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + -6 * F_SCALE);
        gl.glVertex2f(i + 23 * F_SCALE, j + -6 * F_SCALE);
        gl.glVertex2f(i + 26 * F_SCALE, j + -15 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -34 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -36 * F_SCALE);
        gl.glVertex2f(i + 28 * F_SCALE, j + -38 * F_SCALE);
        gl.glVertex2f(i + 25 * F_SCALE, j + -38 * F_SCALE);
        gl.glEnd();

        //Draw Right Leg of Waste
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 34 * F_SCALE, j + -1 * F_SCALE);
        gl.glVertex2f(i + 39 * F_SCALE, j + -16 * F_SCALE);
        gl.glVertex2f(i + 40 * F_SCALE, j + -27 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -29 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 40 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 37 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 35 * F_SCALE, j + -32 * F_SCALE);
        gl.glVertex2f(i + 28 * F_SCALE, j + -18 * F_SCALE);

        //gl.glColor3f(0f, 0f, 0f);
        gl.glVertex2f(i + 26 * F_SCALE, j + -15 * F_SCALE);
        gl.glVertex2f(i + 23 * F_SCALE, j + -6 * F_SCALE);
        //gl.glColor3f(1f, 1f, 1f);
        gl.glVertex2f(i + 34 * F_SCALE, j + -1 * F_SCALE);
        gl.glEnd();



    }


        public void testBall(GL gl, int i, int j, double value) {

        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);

        //value = 24;
       //fillStat(gl);

        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);

        //System.out.println(i * F_SCALE + 12);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 16 * F_SCALE, j + -65 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + -56 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -56 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -65 * F_SCALE);


        gl.glEnd();

    }






        private void drawBallProtection(GL gl, int i, int j, double value)
    {

        /*
         * 1 = RED
         * 2 = ORANGE
         * 3 = YELLOW
         * 4 = GREEN
         */


        if(value == 1)
            ball = loadTexture("src/org/rowan/infovis/soccer/soccer-red.png");
        else if(value == 2)
            ball = loadTexture("src/org/rowan/infovis/soccer/soccer-orange.png");
        else if(value == 3)
            ball = loadTexture("src/org/rowan/infovis/soccer/soccer-yellow.png");
        else if(value == 4)
            ball = loadTexture("src/org/rowan/infovis/soccer/soccer-green.png");
        else
            ball = loadTexture("src/org/rowan/infovis/soccer/soccer.png");



        gl.glColor3f(1f, 1f, 1f);

        gl.glEnable(gl.GL_BLEND);
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA);

        TextureCoords tc = ball.getImageTexCoords();
        float left = tc.left();
        float bottom = tc.bottom();
        float right = tc.right();
        float top = tc.top();

        ball.enable();
        ball.bind();

        gl.glPushMatrix();
        gl.glBegin(GL.GL_QUADS);
        gl.glTexCoord2f(left, bottom);
        gl.glVertex2f(i + 2 * F_SCALE, j + -65 * F_SCALE);
        gl.glTexCoord2f(left, top);
        gl.glVertex2f(i + 2 * F_SCALE, j + -56 * F_SCALE);
        gl.glTexCoord2f(right, top);
        gl.glVertex2f(i + 16 * F_SCALE, j + -56 * F_SCALE);
        gl.glTexCoord2f(right, bottom);
        gl.glVertex2f(i + 16 * F_SCALE, j + -65 * F_SCALE);
        gl.glEnd();


        ball.disable();

        gl.glDisable(gl.GL_BLEND);

                gl.glPopMatrix();


    }


    public void drawFace(GL gl, int i, int j, double value) {

        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);

        //value = 24;
       //fillStat(gl);

        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);

        //System.out.println(i * F_SCALE + 12);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 21 * F_SCALE, j + 34 * F_SCALE);
        gl.glVertex2f(i + 20 * F_SCALE, j + 30 * F_SCALE);
        gl.glVertex2f(i + 18 * F_SCALE, j + 28 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 27 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 27 * F_SCALE);
        gl.glVertex2f(i + 14 * F_SCALE, j + 28 * F_SCALE);
        gl.glVertex2f(i + 13 * F_SCALE, j + 32 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 12 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 13 * F_SCALE, j + 36 * F_SCALE);
        gl.glVertex2f(i + 14 * F_SCALE, j + 36 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 38 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 38 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 35 * F_SCALE);
        gl.glVertex2f(i + 18 * F_SCALE, j + 36 * F_SCALE);
        gl.glVertex2f(i + 19 * F_SCALE, j + 34 * F_SCALE);
        gl.glVertex2f(i + 20 * F_SCALE, j + 35 * F_SCALE);
        gl.glVertex2f(i + 21 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 21 * F_SCALE, j + 35 * F_SCALE);


        gl.glEnd();

    }

    public void drawHead(GL gl, int i, int j, double value) {

        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);


        fillStat(gl, value);

        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);


        //System.out.println(i * F_SCALE + 12);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 21 * F_SCALE, j + 35 * F_SCALE);
        gl.glVertex2f(i + 21 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 20 * F_SCALE, j + 35 * F_SCALE);
        gl.glVertex2f(i + 19 * F_SCALE, j + 34 * F_SCALE);
        gl.glVertex2f(i + 18 * F_SCALE, j + 36 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 35 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 38 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 38 * F_SCALE);
        gl.glVertex2f(i + 14 * F_SCALE, j + 36 * F_SCALE);
        gl.glVertex2f(i + 13 * F_SCALE, j + 36 * F_SCALE);
        gl.glVertex2f(i + 12 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + 37 * F_SCALE);

        gl.glVertex2f(i + 11 * F_SCALE, j + 39 * F_SCALE);
        gl.glVertex2f(i + 12 * F_SCALE, j + 41 * F_SCALE);
        gl.glVertex2f(i + 13 * F_SCALE, j + 42 * F_SCALE);
        gl.glVertex2f(i + 14 * F_SCALE, j + 43 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 43 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 43 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 43 * F_SCALE);
        gl.glVertex2f(i + 18 * F_SCALE, j + 42 * F_SCALE);
        gl.glVertex2f(i + 19 * F_SCALE, j + 41 * F_SCALE);
        gl.glVertex2f(i + 21 * F_SCALE, j + 39 * F_SCALE);

        gl.glEnd();


        //Draw Outline
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 21 * F_SCALE, j + 35 * F_SCALE);
        gl.glVertex2f(i + 21 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 20 * F_SCALE, j + 35 * F_SCALE);
        gl.glVertex2f(i + 19 * F_SCALE, j + 34 * F_SCALE);
        gl.glVertex2f(i + 18 * F_SCALE, j + 36 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 35 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 38 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 38 * F_SCALE);
        gl.glVertex2f(i + 14 * F_SCALE, j + 36 * F_SCALE);
        gl.glVertex2f(i + 13 * F_SCALE, j + 36 * F_SCALE);
        gl.glVertex2f(i + 12 * F_SCALE, j + 37 * F_SCALE);
        gl.glVertex2f(i + 11 * F_SCALE, j + 37 * F_SCALE);

        gl.glVertex2f(i + 11 * F_SCALE, j + 39 * F_SCALE);
        gl.glVertex2f(i + 12 * F_SCALE, j + 41 * F_SCALE);
        gl.glVertex2f(i + 13 * F_SCALE, j + 42 * F_SCALE);
        gl.glVertex2f(i + 14 * F_SCALE, j + 43 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 43 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 43 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 43 * F_SCALE);
        gl.glVertex2f(i + 18 * F_SCALE, j + 42 * F_SCALE);
        gl.glVertex2f(i + 19 * F_SCALE, j + 41 * F_SCALE);
        gl.glVertex2f(i + 21 * F_SCALE, j + 39 * F_SCALE);
        gl.glEnd();



    }

    public void drawLeftFoot(GL gl, int i, int j, double value) {

        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);

        fillStat(gl, value);

        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);


        //Draw Upper Leg
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 25 * F_SCALE, j + -38 * F_SCALE);
        gl.glVertex2f(i + 28 * F_SCALE, j + -38 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -36 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -34 * F_SCALE);
        gl.glVertex2f(i + 32 * F_SCALE, j + -37 * F_SCALE);
        gl.glVertex2f(i + 33 * F_SCALE, j + -37 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -55 * F_SCALE);
        gl.glVertex2f(i + 36 * F_SCALE, j + -55 * F_SCALE);

        /*
        gl.glVertex2f(i + 43 * F_SCALE, j + -58 * F_SCALE);
        gl.glVertex2f(i + 43 * F_SCALE, j + -64 * F_SCALE);
        gl.glVertex2f(i + 42 * F_SCALE, j + -65 * F_SCALE);
        gl.glVertex2f(i + 37 * F_SCALE, j + -64 * F_SCALE);
        gl.glVertex2f(i + 38 * F_SCALE, j + -61 * F_SCALE);
        gl.glVertex2f(i + 38 * F_SCALE, j + -58 * F_SCALE);
        gl.glVertex2f(i + 36 * F_SCALE, j + -55 * F_SCALE);
*/

        gl.glEnd();

        //Draw Foot
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 43 * F_SCALE, j + -58 * F_SCALE);
        gl.glVertex2f(i + 43 * F_SCALE, j + -64 * F_SCALE);
        gl.glVertex2f(i + 42 * F_SCALE, j + -65 * F_SCALE);
        gl.glVertex2f(i + 37 * F_SCALE, j + -64 * F_SCALE);
        gl.glVertex2f(i + 38 * F_SCALE, j + -61 * F_SCALE);
        gl.glVertex2f(i + 38 * F_SCALE, j + -58 * F_SCALE);
        gl.glVertex2f(i + 36 * F_SCALE, j + -55 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -55 * F_SCALE);
        gl.glEnd();



        //DRAW OUTLINE OF THE LEG AND FOOT
        //Draw Top Leg
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 25 * F_SCALE, j + -38 * F_SCALE);
        gl.glVertex2f(i + 28 * F_SCALE, j + -38 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -36 * F_SCALE);
        gl.glVertex2f(i + 30 * F_SCALE, j + -34 * F_SCALE);
        gl.glVertex2f(i + 32 * F_SCALE, j + -37 * F_SCALE);
        gl.glVertex2f(i + 33 * F_SCALE, j + -37 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -55 * F_SCALE);
        gl.glVertex2f(i + 36 * F_SCALE, j + -55 * F_SCALE);
        gl.glEnd();

        //Draw Foot
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 43 * F_SCALE, j + -58 * F_SCALE);
        gl.glVertex2f(i + 43 * F_SCALE, j + -64 * F_SCALE);
        gl.glVertex2f(i + 42 * F_SCALE, j + -65 * F_SCALE);
        gl.glVertex2f(i + 37 * F_SCALE, j + -64 * F_SCALE);
        gl.glVertex2f(i + 38 * F_SCALE, j + -61 * F_SCALE);
        gl.glVertex2f(i + 38 * F_SCALE, j + -58 * F_SCALE);
        gl.glVertex2f(i + 36 * F_SCALE, j + -55 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -55 * F_SCALE);
        gl.glEnd();


    }

    public void drawRightFoot(GL gl, int i, int j, double value) {

        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);

        gl.glColor3f(1f, 1f, 1f);

        fillStat(gl, value);

        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 35 * F_SCALE, j + -32 * F_SCALE);
        gl.glVertex2f(i + 37 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 40 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -29 * F_SCALE);
        gl.glVertex2f(i + 40 * F_SCALE, j + -27 * F_SCALE);
        gl.glVertex2f(i + 42 * F_SCALE, j + -31 * F_SCALE);
        gl.glVertex2f(i + 43 * F_SCALE, j + -34 * F_SCALE);
        gl.glVertex2f(i + 50 * F_SCALE, j + -42 * F_SCALE);
        gl.glVertex2f(i + 50 * F_SCALE, j + -46 * F_SCALE);
        gl.glVertex2f(i + 45 * F_SCALE, j + -48 * F_SCALE);
        gl.glVertex2f(i + 38 * F_SCALE, j + -35 * F_SCALE);


        gl.glEnd();


        //Draw Outline
        gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
        gl.glColor3f(1f, 1f, 1f);
        gl.glBegin(gl.GL_POLYGON);
        gl.glVertex2f(i + 35 * F_SCALE, j + -32 * F_SCALE);
        gl.glVertex2f(i + 37 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 40 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -33 * F_SCALE);
        gl.glVertex2f(i + 41 * F_SCALE, j + -29 * F_SCALE);
        gl.glVertex2f(i + 40 * F_SCALE, j + -27 * F_SCALE);
        gl.glVertex2f(i + 42 * F_SCALE, j + -31 * F_SCALE);
        gl.glVertex2f(i + 43 * F_SCALE, j + -34 * F_SCALE);
        gl.glVertex2f(i + 50 * F_SCALE, j + -42 * F_SCALE);
        gl.glVertex2f(i + 50 * F_SCALE, j + -46 * F_SCALE);
        gl.glVertex2f(i + 45 * F_SCALE, j + -48 * F_SCALE);
        gl.glVertex2f(i + 38 * F_SCALE, j + -35 * F_SCALE);
        gl.glEnd();


    }

    public void drawExpression(GL gl, int i, int j) {

        //gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);

        gl.glColor3f(1f, 1f, 1f);


        //head
        //gl.glColor3f(0.96f, 0.96f, 0.86f);


        //System.out.println(i * F_SCALE + 12);
        gl.glBegin(gl.GL_LINES);
        gl.glVertex2f(i + 12 * F_SCALE, j + 34 * F_SCALE);
        gl.glVertex2f(i + 14 * F_SCALE, j + 33 * F_SCALE);
        gl.glEnd();

        gl.glBegin(gl.GL_LINES);
        gl.glVertex2f(i + 15 * F_SCALE, j + 33 * F_SCALE);
        gl.glVertex2f(i + 17 * F_SCALE, j + 34 * F_SCALE);
        gl.glEnd();

        gl.glBegin(gl.GL_LINES);
        gl.glVertex2f(i + 15 * F_SCALE, j + 32 * F_SCALE);
        gl.glVertex2f(i + 15 * F_SCALE, j + 30 * F_SCALE);
        gl.glEnd();

        gl.glBegin(gl.GL_LINES);
        gl.glVertex2f(i + 15 * F_SCALE, j + 30 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 30 * F_SCALE);
        gl.glEnd();

        gl.glBegin(gl.GL_LINES);
        gl.glVertex2f(i + 14 * F_SCALE, j + 28 * F_SCALE);
        gl.glVertex2f(i + 16 * F_SCALE, j + 28 * F_SCALE);
        gl.glEnd();


    }

    public void drawBall(GL gl) {
        gl.glColor3f(1f, 1f, 1f);

        int radius = 120;
        GLU glu = new GLU();
        GLUquadric circle = glu.gluNewQuadric();
        glu.gluQuadricDrawStyle(circle, GLU.GLU_LINE);
        glu.gluDisk(circle, 10, radius, 60, 60);


        gl.glColor3f(0f, 0f, 0f);

        gl.glBegin(GL.GL_LINES);
        gl.glVertex2f(300 + 38 * F_SCALE, 300 + -35 * F_SCALE);
        gl.glVertex2f(300 + 38 * F_SCALE, 300 + -35 * F_SCALE);
        gl.glEnd();

        /*
        gl.glBegin(GL.GL_LINES);
        gl.glVertex2d(radius, 0);
        gl.glVertex2d(-radius, 0);
        gl.glEnd();
         */


        /*
        for (radius = 120; radius >= 30; radius -= 30) {
        circle = glu.gluNewQuadric();
        glu.gluQuadricDrawStyle(circle, GLU.GLU_FILL);
        glu.gluDisk(circle, radius - 1, radius, 60, 60);
        }*/




    }
    private void drawSoccerBall(GL gl)
    {
        ball = loadTexture("src/org/rowan/infovis/soccer/soccer.png");
        gl.glColor3f(1f, 1f, 1f);

        gl.glEnable(gl.GL_BLEND);
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA);

        TextureCoords tc = ball.getImageTexCoords();
        float left = tc.left();
        float bottom = tc.bottom();
        float right = tc.right();
        float top = tc.top();

        ball.enable();
        ball.bind();

        gl.glPushMatrix();
        gl.glBegin(GL.GL_QUADS);
        gl.glTexCoord2f(left, bottom);
        gl.glVertex2f(450, 50);
        gl.glTexCoord2f(left, top);
        gl.glVertex2f(450, 150);
        gl.glTexCoord2f(right, top);
        gl.glVertex2f(550, 150);
        gl.glTexCoord2f(right, bottom);
        gl.glVertex2f(550, 50);
        gl.glEnd();
        gl.glPopMatrix();

        ball.disable();

        gl.glDisable(gl.GL_BLEND);
    }

         

    private Texture loadTexture(String filename)
    {
        Texture texture = null;
        try {
            texture = TextureIO.newTexture(new File(filename), false);
            texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
            texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
        } catch (Exception e) {
            System.out.println("error loading texture from " + filename);
        }

        return texture;
    }

    public void setHeadColorValue(double colorValue)
    {
        this.headColorValue = colorValue;
    }

    public void setArmsColorValue(double colorValue)
    {
        this.armsColorValue = colorValue;
    }

    public void setChestColorValue(double colorValue)
    {
        this.chestColorValue = colorValue;
    }

    public void setTorsoColorValue(double colorValue)
    {
        this.torsoColorValue = colorValue;
    }

    public void setLegsColorValue(double colorValue)
    {
        this.legsColorValue = colorValue;
    }

    public void setFootColorValue(double colorValue)
    {
        this.footColorValue = colorValue;
    }

    public void setSoccerBallColorValue(int colorValue)
    {
        this.soccerBallColorValue = colorValue;
    }

    public void setSoccerBallLocationValue(int locationValue)
    {
        this.soccerBallLocationValue = locationValue;
    }
}
